$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'device/devicedata/list',
        datatype: "json",
        colModel: [
            {label: 'id', name: 'id', index: 'id',hidden:true, width: 50, key: true},
            {label: '设备Id', name: 'deviceId', index: 'deviceId', width: 250},
            {label: 'IMEI', name: 'btImei', index: 'btImei', width: 80},
            /*{label: '数据发生日期', name: 'dataDate', index: 'data_date', width: 80,formatter: function(value, options, row){
                var dt=new Date(value);
                return dt.getFullYear()+"-"+(dt.getMonth()+1)+"-"+(dt.getDay()+1)+" "+dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds();
                }},*/
            {label: '数据发生日期', name: 'dataDate', index: 'data_date', width: 80},
            {label: '位移数据1', name: 'dis1', index: 'dis1', width: 80},
            {label: '位移数据2', name: 'dis2', index: 'dis2', width: 80},
            {label: '倾角1', name: 'q1', index: 'q1', width: 80},
            {label: '倾角2', name: 'q2', index: 'q2', width: 80},
           // {label: '数据类型', name: 'dataType', index: 'data_type', width: 80}

        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        deviceData: {},
        s1: {provinces:[],cities:[],countries:[],buildings:[],province:'',city:'',country:'',buildingName:''},

    },
    mounted:function(){
        this.s1getProvince();
    }
    ,
    methods: {
        query: function () {
            vm.reload();
        },
        s1getProvince: function () {
            var url = baseURL + "device/devicedata/getBuildingArea?level=0";
            var _this=this;
            $.getJSON(url, function (data) {
                _this.s1.provinces = data.data;
            });
        },
        s1getCity: function () {
            var _this=this;
            var url = baseURL + "device/devicedata/getBuildingArea?level=1&parentKey=" + vm.s1.province;
            $.getJSON(url, function (data) {
                _this.s1.cities = data.data;
            });
        },
        s1getCountry: function () {
            var _this=this;
            var url = baseURL + "device/devicedata/getBuildingArea?level=2&parentKey=" + vm.s1.city;
            $.getJSON(url, function (data) {
                _this.s1.countries = data.data;
            });
        },
        s1getBuilding: function () {
            var _this=this;
            var url = baseURL + "device/devicedata/getBuildingArea?level=3&parentKey=" + vm.s1.country;
            $.getJSON(url, function (data) {
                _this.s1.buildings = data.data;
            });
        },

      exportData:function(){
          // $('#jqGrid').jqGrid({"loadonce":true}).trigger("reloadGrid");
          // $("#jqGrid").jqGrid("exportToExcel",{
          //     includeLabels : true,
          //     includeGroupHeader : true,
          //     includeFooter: true,
          //     fileName : "设备数据.xlsx",
          //     replaceStr:function (str) {
          //         return str.replace('<span class="label label-danger">','').replace('</span>',"")
          //             .replace('<span class="label label-success">','');
          //     }
          //     //maxlength : 40 // maxlength for visible string data
          // })
          var url=baseURL+"/device/devicedata/export";
          $.getJSON(url,function (data) {
              window.open(baseURL+ data.file);
          })
      },
        test:function(){
            var filename = "write.xlsx";
            var data = [[1,2,3],[true, false, null, "sheetjs"],["foo","bar",new Date("2014-02-19T14:30Z"), "0.3"], ["baz", null, "qux"]]
            var ws_name = "SheetJS";


            var wb = XLSX.utils.book_new(), ws = XLSX.utils.aoa_to_sheet(data);

            /* add worksheet to workbook */
            XLSX.utils.book_append_sheet(wb, ws, ws_name);

            /* write workbook */
            console.log(new Date());
            XLSX.writeFile(wb, filename);
            console.log(new Date());
        },
        reload: function (event) {
            vm.showList = true;

            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                page: page,
                postData:vm.s1
            }).trigger("reloadGrid");
        }
    }
});